package org.ls.petclinic.dao.impl;

import org.ls.petclinic.dao.CustomerDao;
import org.ls.petclinic.pojo.Customer;

import java.util.List;

/**
 * @Description
 * @Author 浪矢先生
 * @Create 2022-06-10 0:08
 */
public class CustomerDaoImpl extends BaseDao implements CustomerDao {
    @Override
    public int addCustormer(Customer customer) {
        String sql="insert into customer(name,customerGender,phone,address,petName,petGender,createTime,illness,isSeeDoctor)values(?,?,?,?,?,?,?,?,?)";
        return update(sql, customer.getName(),customer.getCustomerGender(),customer.getPhone(),customer.getAddress(),customer.getPetName(),customer.getPetGender(),customer.getCreateTime(),customer.getIllness(),customer.getIsSeeDoctor());
    }

    @Override
    public List<Customer> getCustomer() {
        return queryForList(Customer.class, "select * from customer");
    }

    @Override
    public Customer getCustomerById(int id) {
        return queryForOne(Customer.class, "select * from customer where id= ?", id);
    }

    @Override
    public int deleteCustormer(int id) {
        String sql="delete from customer where id =?";
        return update(sql,id);
    }

    @Override
    public int updateIsSeeDoctorById(int id,String isSeeDoctor) {
        String sql="update customer set isSeeDoctor=? where id= ?";
        return update(sql,isSeeDoctor,id);
    }

    @Override
    public Customer getByName(String name) {
        return queryForOne(Customer.class, "select * from customer where name=?", name);
    }
}
